package com.example.huadi1.controller;

import com.example.huadi1.dto.Textbook;
import com.example.huadi1.service.BuyBookService;
import com.example.huadi1.service.StockChangeService;
import com.example.huadi1.service.TextbookChangeService;
import com.example.huadi1.service.TextbookService;
import com.example.huadi1.utils.AjaxResult;
import com.example.huadi1.utils.Request.LoseRequest;
import com.example.huadi1.utils.Request.SinglePageRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/textbook")
@Slf4j
public class TextbookController {
    @Autowired
    TextbookService textbookService;
    @Autowired
    StockChangeService stockChangeService;
    @Autowired
    TextbookChangeService textbookChangeService;

    @PostMapping("/queryAllTextbook")
    AjaxResult queryAllTextbook(@RequestBody SinglePageRequest singlePageRequest){
        return textbookService.queryTextbook(singlePageRequest);
    }
    @PostMapping("/addTextbook")
    AjaxResult addTextbook(@RequestBody Textbook textbook){
        textbookService.addTextbook(textbook);
        return AjaxResult.success();
    }
    @PostMapping("/deleteTextbook")
    AjaxResult deleteTextbook(@RequestBody Textbook textbook){
        textbookService.deleteTextbook(textbook);
        return AjaxResult.success();
    }
    @PostMapping("/updateTextbook")
    AjaxResult updateTextbook(@RequestBody Textbook textbook){
        System.out.println(textbook);
        textbookService.updateTextbook(textbook);
        return AjaxResult.success();
    }

    @PostMapping("/queryTextbookChange")
    AjaxResult queryTextbookChange(@RequestBody SinglePageRequest singlePageRequest){
        return textbookChangeService.query(singlePageRequest);
    }

    @PostMapping("/queryStockChange")
    AjaxResult queryStockChange(@RequestBody SinglePageRequest singlePageRequest){
        return stockChangeService.query(singlePageRequest);
    }

    @PostMapping("/loseReq")
    AjaxResult loseReq(@RequestBody LoseRequest loseRequest){
        return textbookService.lose(loseRequest);
    }

}
